package com.tensquare.qa.dao;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author Macross
 * @Type ProblemDao.java
 * @Desc 问题信息dao接口
 * @date 2019/12/17 17:19
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem> {

    /**
     * 获取最新问题列表信息,并进行分页[按问题创建时间进行降序排序]
     * @param labelId 标签id
     * @param pageable 分页信息对象
     * @return
     */
    @Query(
            nativeQuery = true,
            value = "select tb_problem.* from tb_pl,tb_problem where problemid = id and labelid = ?1 order by createtime desc"
    )
    Page<Problem> getNewList(String labelId, Pageable pageable);

    /**
     * 获取热门问题信息列表,并进行分页[按点击数进行降序排序]
     * @param labelId 标签id
     * @param pageable 分页信息对象
     * @return
     */
    @Query(
            nativeQuery = true,
            value = "select tb_problem.* from tb_pl,tb_problem where problemid = id and labelid = ?1 order by reply desc"
    )
    Page<Problem> getHotList(String labelId, Pageable pageable);
}
